using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Friso.Entities;
using Friso.Business;
using FetCo.Data;
using FetCo.Framework;
public partial class Admin_ContentEmail : System.Web.UI.Page
{
    #region viewstate
    protected long Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (long)o;
            return long.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }
    Photo _Photo = new Photo();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
        {
            this.Id = long.Parse(Request.QueryString["Id"]);
            LoadData(this.Id);
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        GetInfo();
        if (this.Id != long.MinValue)
        {
            PhotoService.UpdatePhoto(_Photo);
            Response.Redirect("ContentMailList.aspx");

        }
        else
        {
            PhotoService.CreatePhoto(_Photo);
            Response.Redirect("ContentMailList.aspx");
        }
        
    }
    private void GetInfo()
    {
        string fdf = txtName.Text;
        if (this.Id != long.MinValue)
        {
            _Photo = PhotoService.GetPhoto(this.Id);

        }
        else
        {

            _Photo.CreatedDate = DateTime.Now;
            _Photo.Order = 100;

        }

        _Photo.Title_Vn = txtName.Text;
        _Photo.Title_En = txtnameen.Text;
        _Photo.Summary_Vn = fck_ContentVn.Value;
        _Photo.Summary_En = fck_ContentEn.Value;
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ContentMailList.aspx");
    }
    #region LoadData
    private void LoadData(long Id)
    {
        Photo _Photo = PhotoService.GetPhoto(Id);
        if (_Photo != null)
        {
            txtName.Text = _Photo.Title_Vn;
            txtnameen.Text = _Photo.Title_En;
            fck_ContentEn.Value = _Photo.Summary_En;
            fck_ContentVn.Value = _Photo.Summary_Vn;
        }
    }
    
    #endregion
}
